#!/bin/sh

# Slackware build script for Frozen Bubble
# Written by Erik Hanson erik@slackbuilds.org

# Modified by the SlackBuilds.org project
set -e

PRGNAM=frozen-bubble
VERSION=2.1.0
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=`pwd`
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP || exit 1
rm -rf $PRGNAM-$VERSION
tar jxvf $CWD/$PRGNAM-$VERSION.tar.bz2 || exit 1
cd $PRGNAM-$VERSION || exit 1
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS `pkg-config glib-2.0 --cflags`" \
make PREFIX=/usr || exit 1
make install DESTDIR=$PKG PREFIX=/usr || exit 1

mkdir -p $PKG/usr/share/applications $PKG/usr/share/icons/hicolor/16x16 \
  $PKG/usr/share/icons/hicolor/32x32 $PKG/usr/share/icons/hicolor/48x48 \
  $PKG/usr/share/icons/hicolor/64x64
cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop
cp -a icons/$PRGNAM-icon-16x16.png $PKG/usr/share/icons/hicolor/16x16/$PRGNAM.png
cp -a icons/$PRGNAM-icon-32x32.png $PKG/usr/share/icons/hicolor/32x32/$PRGNAM.png
cp -a icons/$PRGNAM-icon-48x48.png $PKG/usr/share/icons/hicolor/48x48/$PRGNAM.png
cp -a icons/$PRGNAM-icon-64x64.png $PKG/usr/share/icons/hicolor/64x64/$PRGNAM.png

mv $PKG/usr/share/man $PKG/usr/man
( cd $PKG/usr/man
  find . -type f -exec chmod 644 {} \;
  find . -type f -exec gzip -9 {} \;
  for i in `find . -type l` ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
)

( cd  $PKG
  find . -name perllocal.pod -o -name ".packlist" -o -name "*.bs" | xargs rm -f
  find . -type d -depth -exec rmdir {} \; 2>/dev/null
)

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a AUTHORS COPYING NEWS README TIPS VERSION $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
